package com.guanjia.web;

import com.guanjia.entity.CreditInformation;
import com.guanjia.entity.User;
import com.guanjia.service.BorrowService;
import com.guanjia.service.UserService;
import com.guanjia.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Controller
public class LoginController {
    @Autowired
    private UserService userService;
    @Autowired
    private BorrowService borrowService;

    /**
     * 跳转至登录页面
     * @return
     */
    @RequestMapping("/login")
    public String login(){
        return "cfgj/login";
    }

    /**
     * 跳转至注册页面
     * @return
     */
    @RequestMapping("/register")
    public String register(){
        return "cfgj/register";
    }

    /**
     * 完成注册
     */

    @RequestMapping("/user/reg")
    public String reg(User user){
        userService.regUser(user);
        return "redirect:/login";
    }

    /**
     * 非空判断
     *
     */
    @ResponseBody
    @RequestMapping("/isnull")
    public String isnull(User user){
         System.out.println(user);
        String result=userService.isnull(user);
        return result;
    }

    /**
     * 跳转至首页
     */
   /* @RequestMapping("/index")
    public String Index(){
        return "cfgj/index";
    }*/

    @RequestMapping("/index")
    public String findnewList(Model model){
        List<CreditInformation> newlist = borrowService.newList();
        model.addAttribute("credit",newlist);
        return "cfgj/index";
    }

}
